function This = mytrim(This)
% mytrim  [Not a public function] Remove leading and trailing NaNs.
%
% Backend IRIS function.
% No help provided.

% -IRIS Toolbox.
% -Copyright (c) 2007-2015 IRIS Solutions Team.

%--------------------------------------------------------------------------

This.Stamp = clock();

x = This.data;
if isempty(x)
    return
end

if isreal(x)
    if ~any(any(isnan(x([1,end],:))))
        return
    end
    nanInx = all(isnan(x(:,:)),2);
else
    realX = real(x);
    imagX = imag(x);
    if ~any(any( isnan(realX([1,end],:)) & isnan(imagX([1,end],:)) ))
        return
    end
    nanInx = all( isnan(realX(:,:)) & isnan(imagX(:,:)) ,2);
end

newSize = size(x);
if all(nanInx)
    This.start = NaN;
    newSize(1) = 0;
    This.data = zeros(newSize);
else
    first = find(~nanInx,1);
    last = find(~nanInx,1,'last');
    x = x(first:last,:);
    newSize(1) = last - first + 1;
    This.data = reshape(x,newSize);
    This.start = This.start + first - 1;
end

end
